package com.woniuxy.config;

import com.woniuxy.entity.MyClass;
import com.woniuxy.entity.Student;
import com.woniuxy.entity.Teacher;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author 罗蔚
 * @Date 2022/4/8 0:44
 * @Description java config配置Bean
 */
@Configuration
public class configureClassBeans {
    /**
    * 配置teacher类的bean
    * <bean id="teacher" class="">
     *     <constructor-arg name="name" value="马宇航"></constructor-arg>
     * </bean>
     */
    @Bean
    public Teacher teacher(){
        // <constructor-arg name="name" value="马宇航"></constructor-arg>
        return new Teacher("马宇航");
    }

    /**
     *配置学生们
     * <util:list id="productionStudents">
     *       <bean class="Student">
     *          <constructor-arg name="name" value="tom"></constructor-arg>
     *       </bean>
     *       <bean class="Student">
     *          <constructor-arg name="name" value="jerry"></constructor-arg>
     *       </bean>
     *       <bean class="Student">
     *           <constructor-arg name="name" value="rose"></constructor-arg>
     *       </bean>
     * </util:list>
     * @return
     */
    @Bean
    public List<Student> madingStudents(){
        List<Student> list = new ArrayList<>();
        list.add(new Student("tom"));
        list.add(new Student("jerry"));
        list.add(new Student("rose"));
        return list;
    }
    @Bean
    public MyClass my86Clazz(Teacher teacher, List<Student> madingStudents){
        MyClass myClass = new MyClass();
        myClass.setName("86期");
        myClass.setTeacher(teacher);
        myClass.setStudents(madingStudents);
        return myClass;
    }

}
